home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 52
/
Volume 52 - JOGO DISK .iso
/
Games
/
skipandgouls.swf
/
scripts
/
__Packages
/
Controller.as
next >
Wrap
Text File
|
2007-10-01
|
8KB
|
220 lines
class Controller
{
static var QUALITY_LOW = 0;
static var QUALITY_MEDIUM = 1;
static var QUALITY_HI = 2;
function Controller(l_mcTimeline)
{
_global.C = this;
this.mcContainer = l_mcTimeline;
this.mcContainer.stop();
this.mcContainer._y = 0;
mx.transitions.OnEnterFrameBeacon.init();
this.oEnterFrameListener = new Object();
this.oEnterFrameListener.onEnterFrame = mx.utils.Delegate.create(this,this.update);
MovieClip.addListener(this.oEnterFrameListener);
sarbakan.sound.SoundManager.init(l_mcTimeline);
this.setQuality();
this.oPackaging = new Packaging(l_mcTimeline.mcPackaging);
this.bRestartGame = false;
this.bEndGame = false;
this.bEndLevelPart = false;
this.nLevelPart = 1;
this.nLevelPartScore = 0;
this.nLevelPartMinutes = 0;
this.nLevelPartSeconds = 0;
this.oUnlockedCodes = SharedObject.getLocal("sbghouls_codes");
}
function initGame(l_bSameLevel, l_bNextPart)
{
this.mcContainer.gotoAndStop("game");
sarbakan.visual.PauseManager.reset();
this.resetElementsID();
if(!l_bSameLevel)
{
if(l_bNextPart)
{
this.nLevelPart = this.nLevelPart + 1;
this.nLevelPartScore = this.oHUD.nScore;
this.nLevelPartMinutes = this.oHUD.nMinutes;
this.nLevelPartSeconds = this.oHUD.nSeconds;
}
if(this.nLevelPart < 4)
{
this.oModel = new maze.MazeModel(maze.MazeData.DIFFICULTY_SETTING[this.nDifficultyLevel].width,maze.MazeData.DIFFICULTY_SETTING[this.nDifficultyLevel]["height" + this.nLevelPart]);
this.oGenerator = new maze.MazeGenerator(this.oModel);
this.oGenerator.generate(false);
}
else
{
this.oModel = new maze.MazeModel(maze.MazeData.BONUS_WIDTH,maze.MazeData.BONUS_HEIGHT);
this.oGenerator = new maze.MazeGenerator(this.oModel);
this.oGenerator.generate(true);
}
}
this.bSamePart = l_bSameLevel;
this.oGameView = new sarbakan.visual.layer.LayerManager(this.oModel.nWidth * maze.MazeData.VIEW_TILE_WIDTH,this.oModel.nHeight * maze.MazeData.VIEW_TILE_HEIGHT,600,300);
this.oCam = this.oGameView.getCamera();
this.oLayerFloor = new sarbakan.visual.layer.Layer(this.mcContainer.mcGame.mcFloor,new sarbakan.visual.activation.GridActivation());
this.oGameView.addLayer(this.oLayerFloor,1,1);
this.oLayerGame = new sarbakan.visual.layer.Layer(this.mcContainer.mcGame.mcMaze,new sarbakan.visual.activation.GridActivation());
this.oGameView.addLayer(this.oLayerGame,1,1);
this.oLayerGame.addCollisionMap(new sarbakan.visual.layer.CollisionMap("floor",this.oLayerGame,12632256));
this.oLayerGame.oCollisionMaps.floor.setNewSource(this.mcContainer.mcGame.mcFloor);
this.oLayerGame.oCollisionMaps.floor.show(100);
this.oLayerBg = new sarbakan.visual.layer.Layer(this.mcContainer.mcGame.mcBg,new sarbakan.visual.activation.NoActivation());
this.oGameView.addLayer(this.oLayerBg,1,1);
this.oSpongeBob = new characters.SpongeBob(this.mcContainer.mcGame.mcMaze.mcSpongeBob);
this.oLayerGame.addDynamicElement(this.oSpongeBob);
this.oCam.lockOn(mx.utils.Delegate.create(this.oSpongeBob,this.oSpongeBob.getCoord),true);
if(this.oUnlockedCodes.data.SYRUP_WATER)
{
if(this.sLastWaterType == "water")
{
this.oWater.mc.removeMovieClip();
}
this.mcContainer.mcGame.mcMaze.gotoAndStop("syrup");
this.sLastWaterType = "syrup";
}
else
{
this.mcContainer.mcGame.mcMaze.gotoAndStop("water");
this.sLastWaterType = "water";
}
this.oWater = new maze.elements.Water(this.mcContainer.mcGame.mcMaze.mcWater);
this.oLayerGame.addDynamicElement(this.oWater);
this.oMazeView = new maze.MazeView(this.oLayerGame,this.oModel);
this.oMazeView.render();
this.oHUD = new HUD(this.mcContainer.mcHUD);
this.oHUD.showGetOut();
this.oHUD.setScore(this.nLevelPartScore);
this.oHUD.setTimer(this.nLevelPartMinutes,this.nLevelPartSeconds);
this.oAmbiance = sarbakan.sound.SoundManager.play("ambiance",maze.MazeData.VOLUME_AMBIANCE,99999,true);
this.oGameView.update();
}
function destroyGame()
{
sarbakan.sound.SoundManager.stop(this.oAmbiance);
this.oGameView.destroy();
delete this.oGameView;
}
function resetElementsID()
{
sarbakan.visual.element.BaseElement.resetID();
sarbakan.visual.element.BaseElement.resetID();
sarbakan.visual.element.BaseElement.resetID();
sarbakan.visual.element.BaseElement.resetID();
sarbakan.visual.element.BaseElement.resetID();
}
function endLevelPart()
{
this.bEndLevelPart = true;
}
function endGame(l_bWin)
{
this.nLevelPart = 1;
this.nLevelPartScore = 0;
this.nLevelPartMinutes = 0;
this.nLevelPartSeconds = 0;
this.oHUD.resetLife();
this.bEndGame = true;
if(l_bWin)
{
_global.C.oPackaging.goto("endGood" + this.nDifficultyLevel);
}
else
{
_global.C.oPackaging.goto("endBad");
}
}
function restartGame()
{
this.bRestartGame = true;
this.bRestarting = true;
}
function restartFadeMiddle()
{
this.destroyGame();
if(this.nLevelPart <= 3)
{
if(this.bRestarting)
{
this.initGame(true,false);
this.bRestarting = false;
}
else
{
this.initGame(false,true);
}
}
}
function restartFadeEnd()
{
this.mcContainer.mcFade.gotoAndPlay("disabled");
}
function setDifficulty(l_nDifficultyLevel)
{
this.nDifficultyLevel = l_nDifficultyLevel;
}
function togglePause()
{
if(sarbakan.visual.PauseManager.bPaused)
{
sarbakan.sound.SoundManager.fade(_global.C.oPackaging.oMusic,sarbakan.sound.SoundManager.FADE_VOLUME,maze.MazeData.VOLUME_MUSIC,15);
}
else
{
sarbakan.sound.SoundManager.fade(_global.C.oPackaging.oMusic,sarbakan.sound.SoundManager.FADE_VOLUME,maze.MazeData.VOLUME_MUSIC / 3,15);
}
this.oGameView.togglePause();
}
function unlockCode(l_sCodeID)
{
if(l_sCodeID == "RESET")
{
for(var _loc2_ in this.oUnlockedCodes.data)
{
this.oUnlockedCodes.data[_loc2_] = false;
}
}
else
{
this.oUnlockedCodes.data[l_sCodeID] = true;
}
}
function update()
{
if(this.bRestartGame || this.bEndLevelPart)
{
this.mcContainer.mcFade.gotoAndPlay("fade");
this.bRestartGame = false;
this.bEndLevelPart = false;
}
if(this.bEndGame)
{
this.destroyGame();
this.bEndGame = false;
}
if(this.oGameView)
{
this.oGameView.update();
this.oHUD.update();
}
else
{
this.oPackaging.update();
}
}
function setQuality()
{
if(_global.PerformanceTestResult >= 20)
{
this.nQuality = Controller.QUALITY_MEDIUM;
}
else
{
this.nQuality = Controller.QUALITY_LOW;
}
}
}